home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_13_04
/
allison
/
swap.cpp
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
Macintosh to JP
NeXTSTEP
RISC OS/Acorn
Shift JIS
UTF-8
Wrap
C/C++ Source or Header
|
1995-02-06
|
352 b
|
27 lines
LISTING 7 - A swap function that illustrates call-by-reference
// swap.cpp
#include <stdio.h>
void swap(int &, int &);
main()
{
int i = 1, j = 2;
swap(i,j);
printf("i == %d, j == %d\n",i,j);
return 0;
}
void swap(int &x, int &y)
{
int temp = x;
x = y;
y = temp;
}
// Output:
i == 2, j == 1